-- update_timer
--
local import = import
---@type behavior_ret
local bret = import('bt/bt_plugin/behavior3/behavior_ret')
---@type WAIT_TIMER_TYPE
local WAIT_TIMER_TYPE = import('bt/custom_node/enum_type_cfg/WAIT_TIMER_TYPE')
local M = {
    name = "update_timer",
    type = "Action",
    desc = "刷新计时器",
    args = {
        {
            name = 'name',
            type = 'enum?',
            desc = '计时器类型',
            options = WAIT_TIMER_TYPE
        },
    },
    input = { "计时器类型?" },
    output = { "时间?" },
    doc = [[
        + 单位秒
    ]]
}

function M.run(node, env, value)
    local name = node.args.name
    local owner = env.owner
    local ctx = env.ctx
    if value then
        name = value
    end
    if not owner.nodeTimers[name] then
        owner.nodeTimers[name] = 0
    end
    owner.nodeTimers[name] = owner.nodeTimers[name] + ctx.realDeltaTime
    if owner.nodeTimers[name] then
        --xxmsg("owner.nodeTimers = " .. owner.nodeTimers[name] .. ", ctx.realDeltaTime = " .. ctx.realDeltaTime)
    end
    return bret.SUCCESS, owner.nodeTimers[name]
end

return M
